package dabs.engine;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;
import dabs.engine.control.GameCommand;

public class SavingAndLoading {

	GameEngine geng;
	DummyInterface dinterface;
	
	@Before
	public void setUp() throws Exception {
		geng = new GameEngine();
		dinterface = new DummyInterface();
		geng.getPostOffice().registerHandler(dinterface);
	}

	@Test
	public void testRunCommand() {
		geng.tick();
		geng.tick();
		assertEquals(2, geng.getValue());
	}
	
	@Test
	public void testNotification() throws Exception {
		geng.tick();
		geng.getEnvironment().generateDisable(10);
		for (int i = 0; i <= 20; ++i)
			geng.tick();
		System.out.println(dinterface);
		assertTrue(dinterface.get().getDescription().contains("stalling in"));
		
	}
	
	@Test
	public void testSaveandLoad() {
		geng.tick();
		geng.tick();
		geng.runCommand(new GameCommand("save"));
		geng.tick();
		geng.tick();
		geng.runCommand(new GameCommand("load"));
		assertEquals(2, geng.getValue());
	}
	
	@Test (expected= IndexOutOfBoundsException.class)
	public void testException() {
		geng.getPowerPlant().getComponents().get(100);
	}

	
	

}
